package com.stone.business.equipment.action;

/**
 * 设备
 * <pre>
 * @since:2010/02/10
 * </pre>
 */
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import net.sf.json.JSON;
import net.sf.json.JSONSerializer;
import net.sf.json.JsonConfig;

import com.stone.business.equipment.pojo.TEquipmentBase;
import com.stone.business.equipment.pojo.TEquipmentParamByq;
import com.stone.business.equipment.pojo.TEquipmentParamByqBtqtjdq;
import com.stone.business.equipment.pojo.TEquipmentParamByqCyg;
import com.stone.business.equipment.pojo.TEquipmentParamByqFj;
import com.stone.business.equipment.pojo.TEquipmentParamByqLqq;
import com.stone.business.equipment.pojo.TEquipmentParamByqQyb;
import com.stone.business.equipment.pojo.TEquipmentParamByqTg;
import com.stone.business.equipment.pojo.TEquipmentParamByqTyzz;
import com.stone.business.equipment.pojo.TEquipmentParamByqYljdq;
import com.stone.business.equipment.pojo.TEquipmentParamByqYlsff;
import com.stone.business.equipment.pojo.TEquipmentParamByqYzjdq;
import com.stone.business.equipment.pojo.TEquipmentParamDkq;
import com.stone.business.equipment.pojo.TEquipmentParamDlhgq;
import com.stone.business.equipment.pojo.TEquipmentParamDlhgqRz;
import com.stone.business.equipment.pojo.TEquipmentParamDlq;
import com.stone.business.equipment.pojo.TEquipmentParamDrq;
import com.stone.business.equipment.pojo.TEquipmentParamDyhgq;
import com.stone.business.equipment.pojo.TEquipmentParamDyhgqRz;
import com.stone.business.equipment.pojo.TEquipmentParamGlkg;
import com.stone.business.equipment.pojo.TEquipmentParamKgg;
import com.stone.business.equipment.pojo.TEquipmentParamKyj;
import com.stone.business.equipment.pojo.TEquipmentParamMx;
import com.stone.business.equipment.pojo.TEquipmentParamQt;
import com.stone.business.equipment.pojo.TEquipmentParamSb;
import com.stone.business.equipment.pojo.TEquipmentParamXhxq;
import com.stone.business.equipment.pojo.TEquipmentParamZhdq;
import com.stone.business.equipment.service.EquipmentCommonService;
import com.stone.common.pojo.TFile;
import com.stone.common.service.FileService;
import com.stone.para.IConstant;
import com.stone.utils.JsonUtils;
import com.stone.utils.StringUtils;

import frm.ssh.action.BaseListAction;
import frm.ssh.exception.AppException;
import frm.ssh.util.page.Page;

public class EquipmentAction extends BaseListAction {

	private static final long serialVersionUID = 865527685459140622L;

	private EquipmentCommonService myService;
	private FileService fileService;
	
	// 设备基本信息
	private TEquipmentBase entity;

	// 变压器
	private TEquipmentParamByq paramByq;

	// 变压器 风机
	private TEquipmentParamByqFj paramByqFj;

	// 变压器 冷却器
	private TEquipmentParamByqLqq paramByqLqq;

	// 变压器 储油柜
	private TEquipmentParamByqCyg paramByqCyg;

	// 变压器 压力释放阀
	private TEquipmentParamByqYlsff paramByqYlsff;

	// 变压器 有载开关气体继电器
	private TEquipmentParamByqYzjdq paramByqYzjdq;

	// 本体气体继电器
	private TEquipmentParamByqBtqtjdq paramByqBtqtjdq;

	// 变压器 油流继电器
	private TEquipmentParamByqYljdq paramByqYljdq;

	// 变压器 潜油泵
	private TEquipmentParamByqQyb paramByqQyb;

	// 变压器 套管
	private TEquipmentParamByqTg paramByqTg;

	// 变压器 调压装置
	private TEquipmentParamByqTyzz paramByqTyzz;
	
	// 断路器
	private TEquipmentParamDlq paramDlq;
	
	// 隔离开关
	private TEquipmentParamGlkg paramGlkg;
	
	// 组合电器
	private TEquipmentParamZhdq paramZhdq;

	// 开关柜其他参数
	private TEquipmentParamKgg paramKgg;
	
	// 电流互感器其他参数
	private TEquipmentParamDlhgq paramDlhgq;
	
	// 电流互感器绕组参数
	private TEquipmentParamDlhgqRz paramDlhgqRz;
	
	// 电压互感器其他参数
	private TEquipmentParamDyhgq paramDyhgq;
	
	// 电压互感器绕组参数
	private TEquipmentParamDyhgqRz paramDyhgqRz;
	// 所变其他参数
	private TEquipmentParamSb paramSb;
	// 电容器其他参数
	private TEquipmentParamDrq paramDrq;
	// 消弧线圈其他参数
	private TEquipmentParamXhxq paramXhxq;
	// 母线其他参数
	private TEquipmentParamMx paramMx;
	// 电抗器其他参数
	private TEquipmentParamDkq paramDkq;
	// 空压机其他参数
	private TEquipmentParamKyj paramKyj;
	// 其它设备其他参数
	private TEquipmentParamQt paramQt;
	private String id;
	
	private String start;
	
	private String limit;
	
	// 设备类型
	private String sblx;
	
	// 模版id
	private String modelid;
	String bdzid = "";
	private String fromId;
	private String targetId;
	
	public EquipmentAction() {
		this.entityClass = TEquipmentBase.class;
	}
	/**
	 * 查询列表
	 */	
	/*public void getEquipList() throws IOException, AppException {

		List<Object> valsList = new ArrayList<Object>();

		super.setPage((String.valueOf((Integer.parseInt(getStart()) / Integer.parseInt(getLimit()) + 1))));
		
		HashMap<String, Object> m = new HashMap<String, Object>();
		
		// 状态
		String conditions = "base.bdzid = bdz.id and bdz.id = jg.bdzid  and base.typeid = jg.id and base.state = jg.state and dic.itemId = base.sblx and dic.itemType='SBLX'";
		
		// 变电站
		if(!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon2())&& !"0".equals(super.getSearchBean().getCon2())) {
			conditions += " and base.bdzid = '" + super.getSearchBean().getCon2() + "'";
		}
		
		// 间隔或者屏柜
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon3()) && !"0".equals(super.getSearchBean().getCon3())) {
			conditions += " AND (jg.id = '" + super.getSearchBean().getCon3() + "' or jg.parentid = '" + super.getSearchBean().getCon3() + "')";
		}
		
		// 电压等级
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon4())) {
			conditions += " AND base.dydj = '" + super.getSearchBean().getCon4() + "'";
		}
		
		// 设备类型
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon5())) {
			conditions += " AND base.sblx = '" + super.getSearchBean().getCon5() + "'";
		}
		
		// 间隔电压
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon7())) {
			conditions += " AND jg.dydj = '" + super.getSearchBean().getCon7() + "'";
		}

		//m.put("cols", "base.id as id,base.state as state, bdz.bdzname as bdzname, base.dydj || 'kV'  as dydjname, jg.jgmc as typename, dic.itemName as sblxname, base.tyrq as tyrq, base.yxbh as yxbh,base.modelid as modelid");
		m.put("cols", "base.id as id,base.state as state,jg.jgmc||base.yxbh||dic.itemName as sbname, bdz.bdzname as bdzname, base.dydj || 'kV'  as dydjname, jg.jgmc as typename, dic.itemName as sblxname, base.tyrq as tyrq, base.yxbh as yxbh,base.modelid as modelid");
		m.put("alias", " base, TBdz bdz, TBdzJg jg, TDictionary dic");
		m.put("conditions",conditions);
		m.put("clause", " order by base.id");
		
		// 根据起始记录查询当前页记录
		List<HashMap<String,Object>> list = myService.getPageListByDHql(Integer.parseInt(getStart()), Integer.parseInt(getLimit()) , m, TEquipmentBase.class.getName() );
	
        JsonConfig jsonConfig = JsonUtils.configJson(new String[] {}, "yyyy-MM-dd");
    	
        JSON json = JSONSerializer.toJSON(list, jsonConfig);

		String rtn = "{result:" + json.toString() + ",totalCount:[" + myService.getTotalByDHql(conditions, null, TEquipmentBase.class.getName() + m.get("alias")  ) + "]}";
		
        super.getResponse().getWriter().print(rtn);

//		List<HashMap<String, Object>> list = myService.getListByDHql("base.id as id,base.state as state, bdz.bdzname as bdzname, base.dydj || 'kV'  as dydjname, jg.jgmc as typename, dic.itemName as sblxname", 
//				conditions , valsList.toArray(), "order by base.id", "TEquipmentBase base, TBdz bdz, TBdzJg jg, TDictionary dic");
//		

//		
//		JsonConfig jsonConfig = JsonUtils.configJson(new String[] {}, "yyyy-MM-dd");
//    	
//        JSON json = JSONSerializer.toJSON(list, jsonConfig);
//
//		String strjson = "{result:" + json.toString() + ",totalCount:[" + list.size() + "]}";
//		
//        super.getResponse().getWriter().print(strjson);
		
	}*/
	public void getEquipList() throws IOException, AppException {

		
		
		// 状态
		String conditions = "base.bdzid = bdz.id and bdz.id = jg.bdzid  and base.typeid = jg.id and base.state = jg.state and dic.item_Id = base.sblx and dic.item_Type='SBLX'";
		
		// 变电站
		if(!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon2())&& !"0".equals(super.getSearchBean().getCon2())) {
			conditions += " and base.bdzid = '" + super.getSearchBean().getCon2() + "'";
		}
		
		// 间隔或者屏柜
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon3()) && !"0".equals(super.getSearchBean().getCon3())) {
			conditions += " AND (jg.id = '" + super.getSearchBean().getCon3() + "' or jg.parentid = '" + super.getSearchBean().getCon3() + "')";
		}
		
		// 电压等级
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon4())) {
			conditions += " AND base.dydj = '" + super.getSearchBean().getCon4() + "'";
		}
		
		// 设备类型
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon5())) {
			conditions += " AND base.sblx = '" + super.getSearchBean().getCon5() + "'";
		}
		
		// 间隔电压
		if (!StringUtils.isNullOrBlankFull(super.getSearchBean().getCon7())) {
			conditions += " AND jg.dydj = '" + super.getSearchBean().getCon7() + "'";
		}

	   Page page = new Page();

		page.setStartRs(Integer.parseInt(getStart()));
		page.setPerPage(Integer.parseInt(getLimit()));
		page.setObject(new HashMap());
		System.out.println(getStart()+":"+getLimit());
		StringBuffer sql = new StringBuffer();
		
		sql.append("select base.id as id,base.state as state,case when jg.state='1' then jg.jgmc else (select jgmc||jgbh  from sys_bdz_jg a where a.id=jg.parentid) end ||base.yxbh||dic.item_Name as sbname, bdz.bdzname as bdzname, base.dydj || 'kV'  as dydjname, jg.jgmc as typename, dic.item_Name as sblxname, base.tyrq as tyrq, base.yxbh as yxbh,base.modelid as modelid");
		sql.append(" from TAB_EQUIPMENT_BASE base,sys_bdz bdz, sys_bdz_jg jg, sys_dictionary dic");
		sql.append(" where ");
		sql.append(conditions);

		// 根据起始记录查询当前页记录
		List<HashMap<String, Object>> list = myService.getPageListBySQL(page, sql.toString());

		JsonConfig jsonConfig = JsonUtils.configJson(new String[] {}, "yyyy-MM-dd");

		JSON json = JSONSerializer.toJSON(list, jsonConfig);

		String strTree = "{result:" + json.toString() + ",totalCount:["+ service.getTotalBySql(sql.toString()) + "]}";

		super.getResponse().getWriter().print(strTree);

		
	}
	/**
	 * 取得基本信息
	 */
	public void initBaseInfo() throws IOException, AppException {
		super.getResponse().setContentType("text/html;charset=UTF-8");

		List<Object> rtn = new ArrayList<Object>();

		this.entity = (TEquipmentBase) myService.findById(Long.parseLong(id), TEquipmentBase.class.getName());
		System.out.println("modelid=="+modelid);
		if (!"undefined".equals(this.modelid)) {
			//this.entity.setModelid(entity.getId());
			this.entity.setModelid(Long.parseLong(this.modelid));
		}
		
		rtn.add(this.entity);

		// 变压器
		if ("001".equals(entity.getSblx())) {

			List<TEquipmentParamByq> list = myService.findListByHql("from TEquipmentParamByq where baseid = '" + entity.getId() + "'");
			rtn.add(list.get(0));
			
			// 断路器
		} else if ("002".equals(entity.getSblx())) {
			
			List<TEquipmentParamDlq> list = myService.findListByHql("from TEquipmentParamDlq where baseid = '" + entity.getId() + "'");
			rtn.add(list.get(0));
			
			// 隔离开关
		} else if ("003".equals(entity.getSblx())) {
			
			List<TEquipmentParamKgg> list = myService.findListByHql("from TEquipmentParamGlkg where baseid = '" + entity.getId() + "'");
			rtn.add(list.get(0));
			
			// 组合电器
		} else if ("004".equals(entity.getSblx())) {
			
			List<TEquipmentParamZhdq> list = myService.findListByHql("from TEquipmentParamZhdq where baseid = '" + entity.getId() + "'");
			rtn.add(list.get(0));

			// 开关柜
		} else if ("005".equals(entity.getSblx())) {
			
			List<TEquipmentParamKgg> list = myService.findListByHql("from TEquipmentParamKgg where baseid = '" + entity.getId() + "'");
			rtn.add(list.get(0));
			
			// 电流互感器
		} else if ("006".equals(entity.getSblx())) {
				
			List<TEquipmentParamDlhgq> list = myService.findListByHql("from TEquipmentParamDlhgq where baseid = '" + entity.getId() + "'");
			rtn.add(list.get(0));
				
			// 电压互感器
		} else if ("007".equals(entity.getSblx())) {
				
			List<TEquipmentParamDyhgq> list = myService.findListByHql("from TEquipmentParamDyhgq where baseid = '" + entity.getId() + "'");
			rtn.add(list.get(0));	
			// 所变
	    } else if ("021".equals(entity.getSblx())) {
		
		List<TEquipmentParamSb> list = myService.findListByHql("from TEquipmentParamSb where baseid = '" + entity.getId() + "'");
		rtn.add(list.get(0));	
	    	// 电容器
	    } else if ("019".equals(entity.getSblx())) {
		
		List<TEquipmentParamDrq> list = myService.findListByHql("from TEquipmentParamDrq where baseid = '" + entity.getId() + "'");
		rtn.add(list.get(0));	
	    	// 消弧线圈
	    } else if ("022".equals(entity.getSblx())) {
		
		List<TEquipmentParamXhxq> list = myService.findListByHql("from TEquipmentParamXhxq where baseid = '" + entity.getId() + "'");
		rtn.add(list.get(0));	
	    	// 母线
	    } else if ("023".equals(entity.getSblx())) {
		
		List<TEquipmentParamMx> list = myService.findListByHql("from TEquipmentParamMx where baseid = '" + entity.getId() + "'");
		rtn.add(list.get(0));	
	    	// 电抗器
	    } else if ("020".equals(entity.getSblx())) {
		
		List<TEquipmentParamDkq> list = myService.findListByHql("from TEquipmentParamDkq where baseid = '" + entity.getId() + "'");
		rtn.add(list.get(0));	
	    	
	    	// 空压机
	    } else if ("009".equals(entity.getSblx())) {
		
		List<TEquipmentParamKyj> list = myService.findListByHql("from TEquipmentParamKyj where baseid = '" + entity.getId() + "'");
		rtn.add(list.get(0));	
	    	
	    	// 其它设备
	    } else if ("008".equals(entity.getSblx())) {
		
		List<TEquipmentParamQt> list = myService.findListByHql("from TEquipmentParamQt where baseid = '" + entity.getId() + "'");
		rtn.add(list.get(0));	
	    	
	    }
		
        JsonConfig jsonConfig = JsonUtils.configJson(new String[] {}, "yyyy-MM-dd");
    	
        JSON json = JSONSerializer.toJSON(rtn, jsonConfig);
        
        super.getResponse().getWriter().print(json);
		
	}

	/**
	 * 取得1：N子表信息
	 */
	public void getParamList() throws IOException, AppException {
		
		List list = new ArrayList();
		
		// 电流互感器绕组参数
		if ("006".equals(sblx)) {
		
			list = myService.findListByHql("from TEquipmentParamDlhgqRz where baseid = '" + id + "'");
			
			// 电压互感器绕组参数
		} else if ("007".equals(sblx)) {
				
			list = myService.findListByHql("from TEquipmentParamDyhgqRz where baseid = '" + id + "'");
			
			// 变压器 风机
		} else if ("001-1".equals(sblx)) {
				
			list = myService.findListByHql("from TEquipmentParamByqFj where baseid = '" + id + "'");
			
			// 变压器 冷却器
		} else if ("001-2".equals(sblx)) {
				
			list = myService.findListByHql("from TEquipmentParamByqLqq where baseid = '" + id + "'");
			
			// 变压器 储油柜
		} else if ("001-3".equals(sblx)) {
				
			list = myService.findListByHql("from TEquipmentParamByqCyg where baseid = '" + id + "'");
			
			// 变压器 压力释放阀
		} else if ("001-4".equals(sblx)) {
				
			list = myService.findListByHql("from TEquipmentParamByqYlsff where baseid = '" + id + "'");
			
			// 变压器 有载开关气体继电器
		} else if ("001-5".equals(sblx)) {
				
			list = myService.findListByHql("from TEquipmentParamByqYzjdq where baseid = '" + id + "'");
			
			// 变压器 本体气体继电器
		} else if ("001-6".equals(sblx)) {
				
			list = myService.findListByHql("from TEquipmentParamByqBtqtjdq where baseid = '" + id + "'");
			
			// 变压器 油流继电器
		} else if ("001-7".equals(sblx)) {
				
			list = myService.findListByHql("from TEquipmentParamByqYljdq where baseid = '" + id + "'");
			
			// 变压器 潜油泵
		} else if ("001-8".equals(sblx)) {
				
			list = myService.findListByHql("from TEquipmentParamByqQyb where baseid = '" + id + "'");
			
			// 变压器 套管
		} else if ("001-9".equals(sblx)) {
				
			list = myService.findListByHql("from TEquipmentParamByqTg where baseid = '" + id + "'");
			
			// 变压器 调压装置
		} else if ("001-10".equals(sblx)) {
				
			list = myService.findListByHql("from TEquipmentParamByqTyzz where baseid = '" + id + "'");
		}

		JsonConfig jsonConfig = JsonUtils.configJson(new String[] {}, "yyyy-MM-dd");
		
		JSON json = JSONSerializer.toJSON(list, jsonConfig);
		
		String strjson = "{result:" + json.toString() + ",totalCount:[" + list.size() + "]}";
		
		super.getResponse().getWriter().print(strjson);
				
	}
	
	/**
	 * 取得设备照片信息
	 */
	public void getPhotoList() throws IOException, AppException {
		
		List list = new ArrayList();
		list = myService.findListByHql("from TFile where tableid = '" + id + "' AND colname = 'TAB_EQUIPMENT_PHOTO'");

		JsonConfig jsonConfig = JsonUtils.configJson(new String[] {}, "yyyy-MM-dd");
		
		JSON json = JSONSerializer.toJSON(list, jsonConfig);
		
		String strjson = "{result:" + json.toString() + ",totalCount:[" + list.size() + "]}";
		
		super.getResponse().getWriter().print(strjson);
				
	}

	/**
	 * 保存设备信息
	 */	
	public void save() throws IOException, AppException {

		List<Object> list = new ArrayList<Object>();
		list.add(entity);
		System.out.println("dddddd>>>>>>>>>>>"+entity.getModelid());
		// 开关柜
		if ("005".equals(entity.getSblx())) {
			list.add(this.paramKgg);
			// 电流互感器
		} else if ("006".equals(entity.getSblx())) {
			list.add(this.paramDlhgq);
			// 电压互感器
		} else if ("007".equals(entity.getSblx())) {
			list.add(this.paramDyhgq);
			// 组合电器
		} else if ("004".equals(entity.getSblx())) {
			list.add(this.paramZhdq);
			// 隔离开关
		} else if ("003".equals(entity.getSblx())) {
			list.add(this.paramGlkg);
			// 断路器
		} else if ("002".equals(entity.getSblx())) {
			list.add(this.paramDlq);
			// 变压器
		} else if ("001".equals(entity.getSblx())) {
			list.add(this.paramByq);
			// 所变 //by wangtao add20120507
		} else if ("021".equals(entity.getSblx())) {
			list.add(this.paramSb);
			//电容器
		} else if ("019".equals(entity.getSblx())) {
			list.add(this.paramDrq);
			// 消弧线圈
		} else if ("022".equals(entity.getSblx())) {
			list.add(this.paramXhxq);
			// 母线
	    } else if ("023".equals(entity.getSblx())) {
		list.add(this.paramMx);
	    	//电抗器
	   } else if ("020".equals(entity.getSblx())) {
		list.add(this.paramDkq);
		
		//空压机
	   } else if ("009".equals(entity.getSblx())) {
			list.add(this.paramKyj);
			
		//其它设备
	   } else if ("008".equals(entity.getSblx())) {
			list.add(this.paramQt);
			
		}


		String rtnmodelid = "";
		if (entity.getModelid() < 0) {
			rtnmodelid = entity.getModelid().toString();
		} else if (entity.getModelid() == 0) { 
			rtnmodelid = "0";
		} else {
			rtnmodelid = String.valueOf(-entity.getModelid());
		}

		String paraid = myService.saveEquip(list);
		String msg = !"".equals(paraid) ? "保存成功" : "保存失败";

		super.getResponse().getWriter().print("{success:true,msg:'" + msg + "',id:'" + entity.getId() + "',paraid:'" + paraid + "',modelid:'" + rtnmodelid + "'}");
		
	}
	
	/**
	 * 保存设备1：N子表信息
	 */	
	public void saveParam() throws IOException, AppException {
		
		String thisid = "";
		
		// 新建
		if ("0".equals(id)) {
			
			// 电流互感器
			if ("006".equals(sblx)) {
				myService.save(this.paramDlhgqRz);
				thisid = this.paramDlhgqRz.getId().toString();
				
				// 电压互感器
			} else if ("007".equals(sblx)) {
				myService.save(this.paramDyhgqRz);
				thisid = this.paramDyhgqRz.getId().toString();
				
				// 变压器 风机
			} else if ("001-1".equals(sblx)) {
				myService.save(this.paramByqFj);
				thisid = this.paramByqFj.getId().toString();
				
				// 变压器 冷却器
			} else if ("001-2".equals(sblx)) {
				myService.save(this.paramByqLqq);
				thisid = this.paramByqLqq.getId().toString();
				
				// 变压器 储油柜
			} else if ("001-3".equals(sblx)) {
				myService.save(this.paramByqCyg);
				thisid = this.paramByqCyg.getId().toString();
				
				// 变压器 压力释放阀
			} else if ("001-4".equals(sblx)) {
				myService.save(this.paramByqYlsff);
				thisid = this.paramByqYlsff.getId().toString();
				
				// 变压器 有载开关气体继电器
			} else if ("001-5".equals(sblx)) {
				myService.save(this.paramByqYzjdq);
				thisid = this.paramByqYzjdq.getId().toString();
				
				// 变压器 本体气体继电器
			} else if ("001-6".equals(sblx)) {
				myService.save(this.paramByqBtqtjdq);
				thisid = this.paramByqBtqtjdq.getId().toString();
				
				// 变压器 油流继电器
			} else if ("001-7".equals(sblx)) {
				myService.save(this.paramByqYljdq);
				thisid = this.paramByqYljdq.getId().toString();
				
				// 变压器 潜油泵
			} else if ("001-8".equals(sblx)) {
				myService.save(this.paramByqQyb);
				thisid = this.paramByqQyb.getId().toString();
				
				// 变压器 套管
			} else if ("001-9".equals(sblx)) {
				myService.save(this.paramByqTg);
				thisid = this.paramByqTg.getId().toString();
				
				// 变压器 调压装置
			} else if ("001-10".equals(sblx)) {
				myService.save(this.paramByqTyzz);
				thisid = this.paramByqTyzz.getId().toString();
			}

			// 修改
		} else {

			// 电流互感器
			if ("006".equals(sblx)) {
				myService.update(this.paramDlhgqRz);
				thisid = this.paramDlhgqRz.getId().toString();
				
				// 电压互感器
			} else if ("007".equals(sblx)) {
				myService.update(this.paramDyhgqRz);
				thisid = this.paramDyhgqRz.getId().toString();
				// 变压器 风机
			} else if ("001-1".equals(sblx)) {
				myService.update(this.paramByqFj);
				thisid = this.paramByqFj.getId().toString();
				
				// 变压器 冷却器
			} else if ("001-2".equals(sblx)) {
				myService.update(this.paramByqLqq);
				thisid = this.paramByqLqq.getId().toString();
				
				// 变压器 储油柜
			} else if ("001-3".equals(sblx)) {
				myService.update(this.paramByqCyg);
				thisid = this.paramByqCyg.getId().toString();
				
				// 变压器 压力释放阀
			} else if ("001-4".equals(sblx)) {
				myService.update(this.paramByqYlsff);
				thisid = this.paramByqYlsff.getId().toString();
				
				// 变压器 有载开关气体继电器
			} else if ("001-5".equals(sblx)) {
				myService.update(this.paramByqYzjdq);
				thisid = this.paramByqYzjdq.getId().toString();
				
				// 变压器 本体气体继电器
			} else if ("001-6".equals(sblx)) {
				myService.update(this.paramByqBtqtjdq);
				thisid = this.paramByqBtqtjdq.getId().toString();
				
				// 变压器 油流继电器
			} else if ("001-7".equals(sblx)) {
				myService.update(this.paramByqYljdq);
				thisid = this.paramByqYljdq.getId().toString();
				
				// 变压器 潜油泵
			} else if ("001-8".equals(sblx)) {
				myService.update(this.paramByqQyb);
				thisid = this.paramByqQyb.getId().toString();
				
				// 变压器 套管
			} else if ("001-9".equals(sblx)) {
				myService.update(this.paramByqTg);
				thisid = this.paramByqTg.getId().toString();
				
				// 变压器 调压装置
			} else if ("001-10".equals(sblx)) {
				myService.update(this.paramByqTyzz);
				thisid = this.paramByqTyzz.getId().toString();
			}
		}
		
		String msg = "".equals(thisid) ? "保存失败" : "保存成功";

		super.getResponse().getWriter().print("{success:true,msg:'" + msg + "',id:'" + thisid + "'}");
		
	}
	
	/**
	 * 删除
	 * @return
	 * @throws AppException
	 */
	public void delete() throws Exception {

		myService.deleteEquip(id);

		super.getResponse().getWriter().print("删除成功");
		
	}

	/**
	 * 删除设备1：N子表信息
	 * @return
	 * @throws AppException
	 */
	public void deleteParam() throws Exception {
		
		// 电流互感器
		if ("006".equals(sblx)) {
			myService.doDelAll(id, TEquipmentParamDlhgqRz.class.getName());
			
			// 电压互感器
		} else if ("007".equals(sblx)) {
			myService.doDelAll(id, TEquipmentParamDyhgqRz.class.getName());
			
			// 变压器 风机
		} else if ("001-1".equals(sblx)) {
			myService.doDelAll(id, TEquipmentParamByqFj.class.getName());
			
			// 变压器 冷却器
		} else if ("001-2".equals(sblx)) {
			myService.doDelAll(id, TEquipmentParamByqLqq.class.getName());
			
			// 变压器 储油柜
		} else if ("001-3".equals(sblx)) {
			myService.doDelAll(id, TEquipmentParamByqCyg.class.getName());
			
			// 变压器 压力释放阀
		} else if ("001-4".equals(sblx)) {
			myService.doDelAll(id, TEquipmentParamByqYlsff.class.getName());
			
			// 变压器 有载开关气体继电器
		} else if ("001-5".equals(sblx)) {
			myService.doDelAll(id, TEquipmentParamByqYzjdq.class.getName());
			
			// 变压器 本体气体继电器
		} else if ("001-6".equals(sblx)) {
			myService.doDelAll(id, TEquipmentParamByqBtqtjdq.class.getName());
			
			// 变压器 油流继电器
		} else if ("001-7".equals(sblx)) {
			myService.doDelAll(id, TEquipmentParamByqYljdq.class.getName());
			
			// 变压器 潜油泵
		} else if ("001-8".equals(sblx)) {
			myService.doDelAll(id, TEquipmentParamByqQyb.class.getName());
			
			// 变压器 套管
		} else if ("001-9".equals(sblx)) {
			myService.doDelAll(id, TEquipmentParamByqTg.class.getName());
			
			// 变压器 调压装置
		} else if ("001-10".equals(sblx)) {
			myService.doDelAll(id, TEquipmentParamByqTyzz.class.getName());
		}
		
		super.getResponse().getWriter().print("删除成功");
		
	}
	
	public void deletePhoto() throws Exception{
		//System.out.println("------delete file id ========" + id);
		//System.out.println("------delete file path ========" + super.getRequest().getRealPath("/") + "upload/equipment_photo");
		
		TFile tf = (TFile) myService.findById(Long.parseLong(id), TFile.class.getName());
		//System.out.println("=====filename=======" + tf.getRealfilename());
		String filePath = super.getRequest().getRealPath("/") + "upload/equipment_photo/" + tf.getRealfilename();
		File f = new File(filePath);
		if (f.exists()) {
			f.delete();
		}
		myService.delete(Long.parseLong(id), TFile.class.getName());
		super.getResponse().getWriter().print("删除成功");
	}

	/**
	 * 左侧变电站树
	 */	
	@SuppressWarnings("unchecked")
	public void getBdzTree6() throws IOException, AppException {
		
		String parentid = super.getRequest().getParameter("parentid");

		List<HashMap<String, Object>> list = null;
		
		// 电压等级
		if ("0".equals(parentid)) {
		
			list = myService.getListByDHql(
					" t.dydj || 'kv'  as id, dic.itemName as text, 0 as leaf,dic.sortid as sortid, 'dydj' as qtip", 
					"t.dydj = dic.itemId and dic.itemType = 'DYDJ'", 
					null, 
					" group by t.dydj,  dic.itemName,dic.sortid order by dic.sortid", 
					" TBdz t, TDictionary dic ");
			
			// 变电站
		} else if (parentid.endsWith("kv")) {
			
			list = myService.getListByDHql(
					" t.id || 'bdz' as id, t.bdzname as text, 0 as leaf, 'bdz' as qtip",  
					" t.dydj = ? ", 
					new Object[] {parentid.replace("kv", "")}, 
					" order by t.sortid", 
					" TBdz t");	
			
			// 间隔电压
		} else if (parentid.endsWith("bdz")) {
			
			list = myService.getListByDHql(
					" t.dydj || 'jgdy' as id, dic.itemName as text, 0 as leaf, 'jgdy' as qtip",  
					"t.dydj = dic.itemId and dic.itemType = 'DYDJ' and t.bdzid= ? ", 
					new Object[] {Long.parseLong(parentid.replace("bdz", ""))}, 
					" group by t.dydj,  dic.itemName,dic.sortid order by dic.sortid", 
					"TBdzJg t, TDictionary dic ");	
			
			// 间隔
		} else if (parentid.endsWith("jgdy")) {
			
			String bdzid = super.getRequest().getParameter("bdzid");

			list = myService.getListByDHql(
					" t.id as id, t.jgmc as text, 0 as leaf, state as state, 'jg' as qtip," +  
					" '" + super.getContextPath() + "/images/article.gif'  as icon" ,
					" t.state ='1' and t.bdzid = ? and t.dydj = ?", 
					new Object[] {Long.parseLong(bdzid.replace("bdz", "")), parentid.replace("jgdy", "")}, 
					" order by t.id", 
					" TBdzJg t");	
			// 屏柜
		} else {
			list = myService.getListByDHql(
					" t.id as id, t.jgmc as text, 1 as leaf, state as state, 'pg' as qtip," +
					"'" + super.getContextPath() + "/images/grid.png' as icon" ,
					" t.parentid = ?", 
					new Object[] {Long.parseLong(parentid)}, 
					" order by t.id", 
					" TBdzJg t");	
		}

        JsonConfig jsonConfig = JsonUtils.configJson(new String[] {}, "yyyy-MM-dd");
    	
        JSON json = JSONSerializer.toJSON(list, jsonConfig);

        super.getResponse().getWriter().print(json.toString());
		
	}
	
	/**
	 * 左侧变电站树
	 */	
	@SuppressWarnings("unchecked")
	public void getBdzTree2() throws IOException, AppException {
		
		String parentid = super.getRequest().getParameter("parentid");

		List<HashMap<String, Object>> list = null;
		
		// 电压等级
		if ("0".equals(parentid)) {
		
			list = myService.getListByDHql(
					" t.dydj || 'kv'  as id, dic.itemName as text, 0 as leaf,dic.sortid as sortid", 
					"t.dydj = dic.itemId and dic.itemType = 'DYDJ'", 
					null, 
					" group by t.dydj,  dic.itemName,dic.sortid order by dic.sortid", 
					" TBdz t, TDictionary dic ");
			
			// 变电站
		} else if (parentid.endsWith("kv")) {
			
			list = myService.getListByDHql(
					" t.id || 'bdz' as id, t.bdzname as text, 0 as leaf", 
					" t.dydj = ? ", 
					new Object[] {parentid.replace("kv", "")}, 
					" order by t.sortid", 
					" TBdz t");	
			
			// 间隔或瓶柜
		} else if (parentid.endsWith("bdz")) {
			
			// 间隔、瓶柜
			list = myService.getListByDHql(
					" t.id || 'pg' as id, t.jgmc as text, 0 as leaf, state as state, " +
					"(case when state = '1' then '" + super.getContextPath() + "/images/article.gif' else '" + super.getContextPath() + "/images/grid.png' end) as icon" ,
					" t.bdzid = ? ", 
					new Object[] {Long.parseLong(parentid.replace("bdz", ""))}, 
					" order by t.state", 
					" TBdzJg t");	
			
			// 间隔或瓶柜
		} else if (parentid.endsWith("pg")) {
			
			String bdzid = super.getRequest().getParameter("bdzid");
			
			// 设备
			list = myService.getListByDHql(
					" t.id as id, t.ccbh as text, 1 as leaf, t.sblx as qtip" ,
					" t.typeid = jg.id and t.state = jg.state and t.bdzid = ? and (jg.id = ? or jg.parentid =?)", 
					new Object[] {Long.parseLong(bdzid.replace("bdz", "")),Long.parseLong(parentid.replace("pg", "")),Long.parseLong(parentid.replace("pg", ""))}, 
					" order by t.id", 
					" TBdzJg jg, TEquipmentBase t");
			
		}

        JsonConfig jsonConfig = JsonUtils.configJson(new String[] {}, "yyyy-MM-dd");
    	
        JSON json = JSONSerializer.toJSON(list, jsonConfig);

        super.getResponse().getWriter().print(json.toString());
		
	}
	/**
	 * 左侧变电站树复选
	 */	
	@SuppressWarnings("unchecked")
	public void getBdzTree3() throws IOException, AppException {
		
		String parentid = super.getRequest().getParameter("parentid");
		
		List<HashMap<String, Object>> list = null;
		
		// 电压等级
		if ("0".equals(parentid)) {
			bdzid = super.getRequest().getParameter("bdzid");
			list = myService.getListByDHql(
					" t.dydj || 'kv'  as id, dic.itemName as text, 0 as leaf,dic.sortid as sortid", 
					"t.dydj = dic.itemId and dic.itemType = 'DYDJ' and t.id=?", 
					new Object[] {Long.parseLong(bdzid)}, 
					" group by t.dydj,  dic.itemName,dic.sortid order by dic.sortid", 
					" TBdz t, TDictionary dic ");
			
			// 变电站
		} else if (parentid.endsWith("kv")) {
			bdzid = super.getRequest().getParameter("bdzid");
			list = myService.getListByDHql(
					" t.id || 'bdz' as id, t.bdzname as text, 0 as leaf", 
					" t.dydj = ? and t.id=?", 
					new Object[] {parentid.replace("kv", ""),Long.parseLong(bdzid)}, 
					" order by t.sortid", 
					" TBdz t");	
			
			// 间隔电压等级
		} else if (parentid.endsWith("bdz")) {
			// bdzid = super.getRequest().getParameter("bdzid");
			/**list = myService.getListByDHql(
					" t.dydj || 'jgdy'  as id, t.dydj || 'kV' as text, 0 as leaf", 
					" t.bdzid = ? and t.parentid=null", 
					new Object[] {Long.parseLong(parentid.replace("bdz", ""))}, 
					" group by t.dydj order by t.dydj", 
					" TBdzJg t");	*/
			list = myService.getListByDHql(
					" t.dydj || 'jgdy' as id, dic.itemName as text, 0 as leaf, 'jgdy' as qtip",  
					"t.dydj = dic.itemId and t.state ='1' and dic.itemType = 'DYDJ' and t.bdzid= ? ", 
					new Object[] {Long.parseLong(parentid.replace("bdz", ""))}, 
					" group by t.dydj,  dic.itemName,dic.sortid order by dic.sortid", 
					"TBdzJg t, TDictionary dic ");	
			// 间隔
		
	} else if (parentid.endsWith("jgdy")) {
		 bdzid = super.getRequest().getParameter("bdzid");
		// 间隔
		list = myService.getListByDHql(
				" t.id || 'jgsb' as id, t.jgmc||t.jgbh as text, 0 as leaf, state as state, " +
				"(case when state = '1' then '" + super.getContextPath() + "/images/article.gif' else '" + super.getContextPath() + "/images/grid.png' end) as icon" ,
				" t.bdzid = ? and t.dydj = ? and t.state ='1' ", 
				new Object[] {Long.parseLong(bdzid.replace("bdz", "")),parentid.replace("jgdy", "")}, 
				" order by t.id", 
				" TBdzJg t");	
		
		// 设备或瓶柜
	} else if (parentid.endsWith("jgsb")) {
			
			//String bdzid = super.getRequest().getParameter("bdzid");
			
			/*// 设备
			list = myService.getListByDHql(
					" t.id as id, t.ccbh as text, 1 as leaf, t.sblx as qtip" ,
					" typeid = ?", 
					new Object[] {Long.parseLong(parentid.replace("jgsb", ""))}, 
					" order by t.id", 
					" TEquipmentBase t");*/
		String conditions = " and typeid ="+Long.parseLong(parentid.replace("jgsb", ""));
		
		StringBuffer sql = new StringBuffer();
		// 一次设备二次设备
		sql.append("SELECT t.id||'' as id, jg.jgmc||t.yxbh||dic.item_Name as text, 1 as leaf, t.sblx as qtip");
		sql.append(" FROM TAB_EQUIPMENT_BASE t, sys_bdz_jg jg, sys_dictionary dic");
		sql.append(" WHERE t.typeid = jg.id and dic.item_Id = t.sblx and dic.item_Type='SBLX' "); //  
		sql.append(conditions);
		
		// 屏柜
		sql.append(" UNION ");
		sql.append("SELECT t.id||'sbpg' as id, t.JGMC as text, 0 as leaf, '000' as qtip");
		sql.append(" FROM sys_bdz_jg t");
		sql.append(" WHERE t.state='2' "); //  
		sql.append(" and t.parentid ="+Long.parseLong(parentid.replace("jgsb", ""))+"");
	    list = myService.findListBySql(sql.toString());
	  
		/*ArrayList arraylist = new ArrayList();
		for(HashMap<String, Object> map:list){
			map.put("checked", false);
			arraylist.add(map);
		}
		list=arraylist;*/
	
		// 设备或瓶柜
	}else if (parentid.endsWith("sbpg")) {
		
		//String bdzid = super.getRequest().getParameter("bdzid");
		
		// 设备
		/*list = myService.getListByDHql(
				" t.id as id, t.ccbh as text, 1 as leaf, t.sblx as qtip" ,
				"  typeid = ?", 
				new Object[] {Long.parseLong(parentid.replace("sbpg", ""))}, 
				" order by t.id", 
				" TEquipmentBase t");*/
		String conditions = " and typeid ="+Long.parseLong(parentid.replace("sbpg", ""));
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT t.id||'' as id, (select jgmc||jgbh  from sys_bdz_jg a where a.id=jg.parentid)||jgmc||t.yxbh||dic.item_Name as text, 1 as leaf, t.sblx as qtip");
		sql.append(" FROM TAB_EQUIPMENT_BASE t, sys_bdz_jg jg, sys_dictionary dic");
		sql.append(" WHERE t.state='2'  and t.typeid = jg.id and dic.item_Id = t.sblx and dic.item_Type='SBLX' "); //  
		sql.append(conditions);
		list = myService.findListBySql(sql.toString());
		/*ArrayList arraylist = new ArrayList();
		for(HashMap<String, Object> map:list){
			map.put("checked", false);
			arraylist.add(map);
		}
		list=arraylist;*/
		
	}
		ArrayList arraylist = new ArrayList();
		for(HashMap<String, Object> map:list){
			map.put("checked", false);
			arraylist.add(map);
		}
		list=arraylist;
    JsonConfig jsonConfig = JsonUtils.configJson(new String[] {}, "yyyy-MM-dd");
	
    JSON json = JSONSerializer.toJSON(list, jsonConfig);
   //System.out.println(json.toString());
    super.getResponse().getWriter().print(json.toString());
	
}
	/**
	 * 左侧变电站树单选
	 */	
	@SuppressWarnings("unchecked")
	public void getBdzTreeOne() throws IOException, AppException {
		
		String parentid = super.getRequest().getParameter("parentid");
		
		List<HashMap<String, Object>> list = null;
		
		// 电压等级
		if ("0".equals(parentid)) {
			bdzid = super.getRequest().getParameter("bdzid");
			list = myService.getListByDHql(
					" t.dydj || 'kv'  as id, dic.itemName as text, 0 as leaf,dic.sortid as sortid", 
					"t.dydj = dic.itemId and dic.itemType = 'DYDJ' and t.id=?", 
					new Object[] {Long.parseLong(bdzid)}, 
					" group by t.dydj,  dic.itemName,dic.sortid order by dic.sortid", 
					" TBdz t, TDictionary dic ");
			
			// 变电站
		} else if (parentid.endsWith("kv")) {
			bdzid = super.getRequest().getParameter("bdzid");
			list = myService.getListByDHql(
					" t.id || 'bdz' as id, t.bdzname as text, 0 as leaf", 
					" t.dydj = ? and t.id=?", 
					new Object[] {parentid.replace("kv", ""),Long.parseLong(bdzid)}, 
					" order by t.sortid", 
					" TBdz t");	
			
			// 间隔电压等级
		} else if (parentid.endsWith("bdz")) {
			// bdzid = super.getRequest().getParameter("bdzid");
			/**list = myService.getListByDHql(
					" t.dydj || 'jgdy'  as id, t.dydj || 'kV' as text, 0 as leaf", 
					" t.bdzid = ? and t.parentid=null", 
					new Object[] {Long.parseLong(parentid.replace("bdz", ""))}, 
					" group by t.dydj order by t.dydj", 
					" TBdzJg t");	*/
			list = myService.getListByDHql(
					" t.dydj || 'jgdy' as id, dic.itemName as text, 0 as leaf, 'jgdy' as qtip",  
					"t.dydj = dic.itemId and t.state ='1' and dic.itemType = 'DYDJ' and t.bdzid= ? ", 
					new Object[] {Long.parseLong(parentid.replace("bdz", ""))}, 
					" group by t.dydj,  dic.itemName,dic.sortid order by dic.sortid", 
					"TBdzJg t, TDictionary dic ");	
			// 间隔
		
	} else if (parentid.endsWith("jgdy")) {
		 bdzid = super.getRequest().getParameter("bdzid");
		// 间隔
		list = myService.getListByDHql(
				" t.id || 'jgsb' as id, t.jgmc||t.jgbh as text, 0 as leaf, state as state, " +
				"(case when state = '1' then '" + super.getContextPath() + "/images/article.gif' else '" + super.getContextPath() + "/images/grid.png' end) as icon" ,
				" t.bdzid = ? and t.dydj = ? and t.state ='1' ", 
				new Object[] {Long.parseLong(bdzid.replace("bdz", "")),parentid.replace("jgdy", "")}, 
				" order by t.id", 
				" TBdzJg t");	
		
		// 设备或瓶柜
	} else if (parentid.endsWith("jgsb")) {
			
			//String bdzid = super.getRequest().getParameter("bdzid");
			
			/*// 设备
			list = myService.getListByDHql(
					" t.id as id, t.ccbh as text, 1 as leaf, t.sblx as qtip" ,
					" typeid = ?", 
					new Object[] {Long.parseLong(parentid.replace("jgsb", ""))}, 
					" order by t.id", 
					" TEquipmentBase t");*/
		String conditions = " and typeid ="+Long.parseLong(parentid.replace("jgsb", ""));
		
		StringBuffer sql = new StringBuffer();
		// 一次设备二次设备
		sql.append("SELECT t.id||'' as id, jg.jgmc||t.yxbh||dic.item_Name as text, 1 as leaf, t.sblx as qtip");
		sql.append(" FROM TAB_EQUIPMENT_BASE t, sys_bdz_jg jg, sys_dictionary dic");
		sql.append(" WHERE t.typeid = jg.id and dic.item_Id = t.sblx and dic.item_Type='SBLX' "); //  
		sql.append(conditions);
		
		// 屏柜
		sql.append(" UNION ");
		sql.append("SELECT t.id||'sbpg' as id, t.JGMC as text, 0 as leaf, '000' as qtip");
		sql.append(" FROM sys_bdz_jg t");
		sql.append(" WHERE t.state='2' "); //  
		sql.append(" and t.parentid ="+Long.parseLong(parentid.replace("jgsb", ""))+"");
	    list = myService.findListBySql(sql.toString());
	  
		/*ArrayList arraylist = new ArrayList();
		for(HashMap<String, Object> map:list){
			map.put("checked", false);
			arraylist.add(map);
		}
		list=arraylist;*/
	
		// 设备或瓶柜
	}else if (parentid.endsWith("sbpg")) {
		
		//String bdzid = super.getRequest().getParameter("bdzid");
		
		// 设备
		/*list = myService.getListByDHql(
				" t.id as id, t.ccbh as text, 1 as leaf, t.sblx as qtip" ,
				"  typeid = ?", 
				new Object[] {Long.parseLong(parentid.replace("sbpg", ""))}, 
				" order by t.id", 
				" TEquipmentBase t");*/
		String conditions = " and typeid ="+Long.parseLong(parentid.replace("sbpg", ""));
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT t.id||'' as id, (select jgmc||jgbh  from sys_bdz_jg a where a.id=jg.parentid)||jgmc||t.yxbh||dic.item_Name as text, 1 as leaf, t.sblx as qtip");
		sql.append(" FROM TAB_EQUIPMENT_BASE t, sys_bdz_jg jg, sys_dictionary dic");
		sql.append(" WHERE t.state='2'  and t.typeid = jg.id and dic.item_Id = t.sblx and dic.item_Type='SBLX' "); //  
		sql.append(conditions);
		list = myService.findListBySql(sql.toString());
		/*ArrayList arraylist = new ArrayList();
		for(HashMap<String, Object> map:list){
			map.put("checked", false);
			arraylist.add(map);
		}
		list=arraylist;*/
		
	}
		/**ArrayList arraylist = new ArrayList();
		for(HashMap<String, Object> map:list){
			map.put("checked", false);
			arraylist.add(map);
		}
		list=arraylist;*/
    JsonConfig jsonConfig = JsonUtils.configJson(new String[] {}, "yyyy-MM-dd");
	
    JSON json = JSONSerializer.toJSON(list, jsonConfig);
    //System.out.println(json.toString());
    super.getResponse().getWriter().print(json.toString());
	
}
	/**
	 * 左侧变电站树
	 */	
	@SuppressWarnings("unchecked")
	public void getBdzTree() throws IOException, AppException {
		
		String parentid = super.getRequest().getParameter("parentid");

		List<HashMap<String, Object>> list = null;
		
		// 电压等级
		if ("0".equals(parentid)) {
		//System.out.println("树1");
			list = myService.getListByDHql(
					" t.dydj || 'kv'  as id, dic.itemName as text, 0 as leaf,dic.sortid as sortid, 'dydj' as qtip", 
					"t.dydj = dic.itemId and dic.itemType = 'DYDJ'", 
					null, 
					" group by t.dydj,  dic.itemName,dic.sortid order by dic.sortid", 
					" TBdz t, TDictionary dic ");
			
			// 变电站
		} else if (parentid.endsWith("kv")) {
			//System.out.println("树2");
			list = myService.getListByDHql(
					" t.id || 'bdz' as id, t.bdzname as text, 0 as leaf, 'bdz' as qtip",  
					" t.dydj = ? ", 
					new Object[] {parentid.replace("kv", "")}, 
					" order by t.sortid", 
					" TBdz t");	
			
			// 间隔电压
		} else if (parentid.endsWith("bdz")) {
			//System.out.println("树3");
		/*	list = myService.getListByDHql(
					" t.dydj || 'jgdy' as id, dic.itemName as text, 0 as leaf, 'jgdy' as qtip",  
					"t.dydj = dic.itemId and dic.itemType = 'DYDJ' and t.bdzid= ? ", 
					new Object[] {Long.parseLong(parentid.replace("bdz", ""))}, 
					" group by t.dydj,  dic.itemName,dic.sortid order by dic.sortid", 
					"TBdzJg t, TDictionary dic ");	
			*/
			/*"list = myService.getListByDHql(
				  distinct t.bdzid||'@'||t.dydj||'jgdy' as id, t.dydj||'kV' as text,0 as leaf,'jgdy' as qtip " ,
					
					//"(case when state = '1' then '" + super.getContextPath() + "/images/article.gif' else '" + super.getContextPath() + "/images/grid.png' end) as icon" ,
					" t.bdzid = ? ", 
					new Object[] {Long.parseLong(parentid.replace("bdz", ""))}, 
					"", 
					" TBdzJg t");	*/
			
			list = myService.getListByDHql(
					"t.bdzid||'@'||t.dydj||'jgdy' as id, dic.itemName as text, 0 as leaf, 'jgdy' as qtip",  
					"t.dydj = dic.itemId and t.state ='1' and dic.itemType = 'DYDJ' and t.bdzid= ? ", 
					new Object[] {Long.parseLong(parentid.replace("bdz", ""))}, 
					" group by t.dydj,t.bdzid,dic.itemName,dic.sortid order by dic.sortid", 
					"TBdzJg t, TDictionary dic ");	
			// 间隔
		} else if (parentid.endsWith("jgdy")) {
			//System.out.println("树4");
			//String bdzid = super.getRequest().getParameter("bdzid");
			String[] dydjId=parentid.replace("jgdy", "").split("@");
			//System.out.println(""+parentid);
			
			list = myService.getListByDHql(
					" t.id as id, t.jgmc||t.jgbh as text, 0 as leaf, state as state, 'jg' as qtip," +  
					" '" + super.getContextPath() + "/images/article.gif'  as icon" ,
					" t.state ='1' and t.bdzid = ? and t.dydj = ?", 
					new Object[] {Long.parseLong(dydjId[0]), dydjId[1].trim()}, 
					" order by t.id", 
					" TBdzJg t");	
			// 屏柜
		} else {
			//System.out.println("树5");
			list = myService.getListByDHql(
					" t.id as id, t.jgmc as text, 1 as leaf, state as state, 'pg' as qtip," +
					"'" + super.getContextPath() + "/images/grid.png' as icon" ,
					" t.parentid = ?", 
					new Object[] {Long.parseLong(parentid)}, 
					" order by t.id", 
					" TBdzJg t");	
		}

        JsonConfig jsonConfig = JsonUtils.configJson(new String[] {}, "yyyy-MM-dd");
    	
        JSON json = JSONSerializer.toJSON(list, jsonConfig);

        super.getResponse().getWriter().print(json.toString());
		
	}
	/**
	 * 弹出变电站树选择
	 */	
	@SuppressWarnings("unchecked")
	public void getselectBdzTree() throws IOException, AppException {
		
		String parentid = super.getRequest().getParameter("parentid");

		List<HashMap<String, Object>> list = null;
		
		// 电压等级
		if ("0".equals(parentid)) {
		
			list = myService.getListByDHql(
					" t.dydj || 'kv'  as id, dic.itemName as text, 0 as leaf,dic.sortid as sortid", 
					"t.dydj = dic.itemId and dic.itemType = 'DYDJ'", 
					null, 
					" group by t.dydj,  dic.itemName,dic.sortid order by dic.sortid", 
					" TBdz t, TDictionary dic ");
			
			// 变电站
		} else if (parentid.endsWith("kv")) {
			
			list = myService.getListByDHql(
					" t.id || 'bdz' as id, t.bdzname as text, 0 as leaf", 
					" t.dydj = ? ", 
					new Object[] {parentid.replace("kv", "")}, 
					" order by t.sortid", 
					" TBdz t");	
			
				
			// 间隔或瓶柜
		}else {
			
			// 间隔、瓶柜
			list = myService.getListByDHql(
					" t.id as id, t.jgmc as text, 1 as leaf, state as state, " +
					"(case when state = '1' then '" + super.getContextPath() + "/images/article.gif' else '" + super.getContextPath() + "/images/grid.png' end) as icon" ,
					" t.bdzid = ? ", 
					new Object[] {Long.parseLong(parentid.replace("bdz", ""))}, 
					" order by t.state", 
					" TBdzJg t");	
			
		}

        JsonConfig jsonConfig = JsonUtils.configJson(new String[] {}, "yyyy-MM-dd");
    	
        JSON json = JSONSerializer.toJSON(list, jsonConfig);

        super.getResponse().getWriter().print(json.toString());
		
	}
	/**
	 * 复制间距下的设备信息
	 * @throws IOException 
	 * @throws CloneNotSupportedException 
	 * @throws AppException 
	 */
	public void copyJgToJg() throws IOException, AppException, CloneNotSupportedException{
		System.out.println("设备："+fromId+"到设备:"+targetId+"复制成功");
		myService.doCopyEquip(fromId, targetId);
		super.getResponse().getWriter().print("复制成功");
	}
	public void copyPgToPg() throws CloneNotSupportedException, IOException,AppException{
		System.out.println("设备："+fromId+"到设备:"+targetId+"复制成功");
		myService.doCopyPgToPg(fromId, targetId);
		super.getResponse().getWriter().print("复制成功");
	}
	public void copyPgToJg() throws CloneNotSupportedException, IOException,AppException{
		System.out.println("设备："+fromId+"到设备:"+targetId+"复制成功");
		myService.doCopyPgToJg(fromId, targetId);
		super.getResponse().getWriter().print("复制成功");
	}	
	public void copyJgToPg() throws CloneNotSupportedException, IOException,AppException{
		System.out.println("设备："+fromId+"到设备:"+targetId+"复制成功");
		myService.doCopyJgToPg(fromId, targetId);
		super.getResponse().getWriter().print("复制成功");
	}	
	//////////by wangtao add 20120428
	public void copySbToJg() throws CloneNotSupportedException, IOException,AppException{
		System.out.println("设备："+fromId+"到设备:"+targetId+"复制成功");
		myService.doCopySbToJg(fromId, targetId);
		super.getResponse().getWriter().print("复制成功");
	}	
	/////////////////////////////
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public void setMyService(EquipmentCommonService myService) {
		this.myService = myService;
		this.service=myService;
	}

	public HashMap<String, Object> setSearchCondition() {
		return null;
	}


	public TEquipmentParamKgg getParamKgg() {
		return paramKgg;
	}


	public void setParamKgg(TEquipmentParamKgg paramKgg) {
		this.paramKgg = paramKgg;
	}


	public TEquipmentBase getEntity() {
		return entity;
	}


	public void setEntity(TEquipmentBase entity) {
		this.entity = entity;
	}

	public String getStart() {
		return start == null ? "0" : start;
	}

	public void setStart(String start) {
		this.start = start;
	}

	public String getLimit() {
		return limit == null ? String.valueOf(IConstant.PAGE_LIMIT) : limit;
	}

	public void setLimit(String limit) {
		this.limit = limit;
	}

	public TEquipmentParamDlhgq getParamDlhgq() {
		return paramDlhgq;
	}

	public void setParamDlhgq(TEquipmentParamDlhgq paramDlhgq) {
		this.paramDlhgq = paramDlhgq;
	}

	public TEquipmentParamDlhgqRz getParamDlhgqRz() {
		return paramDlhgqRz;
	}

	public void setParamDlhgqRz(TEquipmentParamDlhgqRz paramDlhgqRz) {
		this.paramDlhgqRz = paramDlhgqRz;
	}

	public String getSblx() {
		return sblx;
	}

	public void setSblx(String sblx) {
		this.sblx = sblx;
	}

	public TEquipmentParamDyhgq getParamDyhgq() {
		return paramDyhgq;
	}

	public void setParamDyhgq(TEquipmentParamDyhgq paramDyhgq) {
		this.paramDyhgq = paramDyhgq;
	}

	public TEquipmentParamDyhgqRz getParamDyhgqRz() {
		return paramDyhgqRz;
	}

	public void setParamDyhgqRz(TEquipmentParamDyhgqRz paramDyhgqRz) {
		this.paramDyhgqRz = paramDyhgqRz;
	}

	public TEquipmentParamZhdq getParamZhdq() {
		return paramZhdq;
	}

	public void setParamZhdq(TEquipmentParamZhdq paramZhdq) {
		this.paramZhdq = paramZhdq;
	}

	public TEquipmentParamGlkg getParamGlkg() {
		return paramGlkg;
	}

	public void setParamGlkg(TEquipmentParamGlkg paramGlkg) {
		this.paramGlkg = paramGlkg;
	}

	public TEquipmentParamDlq getParamDlq() {
		return paramDlq;
	}

	public void setParamDlq(TEquipmentParamDlq paramDlq) {
		this.paramDlq = paramDlq;
	}
	
	
	public TEquipmentParamByq getParamByq() {
		return paramByq;
	}

	public void setParamByq(TEquipmentParamByq paramByq) {
		this.paramByq = paramByq;
	}

	public TEquipmentParamByqFj getParamByqFj() {
		return paramByqFj;
	}

	public void setParamByqFj(TEquipmentParamByqFj paramByqFj) {
		this.paramByqFj = paramByqFj;
	}

	public TEquipmentParamByqLqq getParamByqLqq() {
		return paramByqLqq;
	}

	public void setParamByqLqq(TEquipmentParamByqLqq paramByqLqq) {
		this.paramByqLqq = paramByqLqq;
	}

	public TEquipmentParamByqCyg getParamByqCyg() {
		return paramByqCyg;
	}

	public void setParamByqCyg(TEquipmentParamByqCyg paramByqCyg) {
		this.paramByqCyg = paramByqCyg;
	}

	public TEquipmentParamByqYlsff getParamByqYlsff() {
		return paramByqYlsff;
	}

	public void setParamByqYlsff(TEquipmentParamByqYlsff paramByqYlsff) {
		this.paramByqYlsff = paramByqYlsff;
	}

	public TEquipmentParamByqYzjdq getParamByqYzjdq() {
		return paramByqYzjdq;
	}

	public void setParamByqYzjdq(TEquipmentParamByqYzjdq paramByqYzjdq) {
		this.paramByqYzjdq = paramByqYzjdq;
	}

	public TEquipmentParamByqBtqtjdq getParamByqBtqtjdq() {
		return paramByqBtqtjdq;
	}

	public void setParamByqBtqtjdq(TEquipmentParamByqBtqtjdq paramByqBtqtjdq) {
		this.paramByqBtqtjdq = paramByqBtqtjdq;
	}

	public TEquipmentParamByqYljdq getParamByqYljdq() {
		return paramByqYljdq;
	}

	public void setParamByqYljdq(TEquipmentParamByqYljdq paramByqYljdq) {
		this.paramByqYljdq = paramByqYljdq;
	}

	public TEquipmentParamByqQyb getParamByqQyb() {
		return paramByqQyb;
	}

	public void setParamByqQyb(TEquipmentParamByqQyb paramByqQyb) {
		this.paramByqQyb = paramByqQyb;
	}

	public TEquipmentParamByqTg getParamByqTg() {
		return paramByqTg;
	}

	public void setParamByqTg(TEquipmentParamByqTg paramByqTg) {
		this.paramByqTg = paramByqTg;
	}

	public TEquipmentParamByqTyzz getParamByqTyzz() {
		return paramByqTyzz;
	}

	public void setParamByqTyzz(TEquipmentParamByqTyzz paramByqTyzz) {
		this.paramByqTyzz = paramByqTyzz;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}

	public EquipmentCommonService getMyService() {
		return myService;
	}

	public String getModelid() {
		return modelid;
	}

	public void setModelid(String modelid) {
		this.modelid = modelid;
	}
	
	public String getFromId() {
		return fromId;
	}

	public void setFromId(String fromId) {
		this.fromId = fromId;
	}

	public String getTargetId() {
		return targetId;
	}

	public void setTargetId(String targetId) {
		this.targetId = targetId;
	}
	public TEquipmentParamSb getParamSb() {
		return paramSb;
	}
	public void setParamSb(TEquipmentParamSb paramSb) {
		this.paramSb = paramSb;
	}
	public TEquipmentParamDrq getParamDrq() {
		return paramDrq;
	}
	public void setParamDrq(TEquipmentParamDrq paramDrq) {
		this.paramDrq = paramDrq;
	}
	public TEquipmentParamXhxq getParamXhxq() {
		return paramXhxq;
	}
	public void setParamXhxq(TEquipmentParamXhxq paramXhxq) {
		this.paramXhxq = paramXhxq;
	}
	public TEquipmentParamMx getParamMx() {
		return paramMx;
	}
	public void setParamMx(TEquipmentParamMx paramMx) {
		this.paramMx = paramMx;
	}
	public TEquipmentParamDkq getParamDkq() {
		return paramDkq;
	}
	public void setParamDkq(TEquipmentParamDkq paramDkq) {
		this.paramDkq = paramDkq;
	}
	public TEquipmentParamKyj getParamKyj() {
		return paramKyj;
	}
	public void setParamKyj(TEquipmentParamKyj paramKyj) {
		this.paramKyj = paramKyj;
	}
	public TEquipmentParamQt getParamQt() {
		return paramQt;
	}
	public void setParamQt(TEquipmentParamQt paramQt) {
		this.paramQt = paramQt;
	}

}
